// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
Vue.use(ElementUI)
import './axios.config'

import global_ from './Global'
Vue.prototype.GLOBAL = global_
import './filter'

import $ from 'jquery'
import 'bootstrap/dist/js/bootstrap.min'

import echarts from 'echarts'
import 'echarts-wordcloud'
import ECharts from 'vue-echarts/components/ECharts.vue'
Vue.component('chart', ECharts)
Vue.prototype.$echarts = echarts
import 'echarts/map/js/china'

import 'bootstrap/dist/css/bootstrap.min.css'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/main.css'
import store from "./store"
import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)

//import './assets/yyh.less'
Vue.config.productionTip = false
import htmlToPdf from './utils/htmlToPdf'
Vue.use(htmlToPdf)

// 切换路由滚动至顶部
router.afterEach(() => {
  document.body.scrollTop = document.documentElement.scrollTop = 0;
});

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => {
    return record.meta.requiresAuth
  })) {
    if (!sessionStorage.getItem("tokenName")) {
      next({
        path: '/login',
        query: { redirect: to.fullPath } // 把要跳转的地址作为参数传到下一步
      })
    } else {
      next()
    }
  } else {
    if (to.query && to.query.redirect) {
      if (sessionStorage.getItem("tokenName")) {
        next({path: to.query.redirect})
      } else {
        next()
      }
    } else {
      next() // 确保一定要调用 next()
    }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
